package com.hysf;

import com.hysf.pojo.Student;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

@RestController
@SpringBootApplication
public class App {
	
	public static void main(String[] args) {
		SpringApplication.run(App.class, args);
	}
	
	@GetMapping("/hello")
	public String hello(@RequestParam(value = "name", defaultValue = "World") String name) {
		return String.format("Hello %s!", name);
	}
	
	@RequestMapping(value = "/hello2", method = RequestMethod.POST)
	public String hello2(@RequestParam(value = "name", defaultValue = "World") String name) {
		System.out.println("调用hello2");
		return String.format("Hello2 %s!", name);
	}
	
	/*
	* 三种参数传递
	* http://localhost:8080/student?math=100&chinese=中文
	* */
	@GetMapping(value = "/student", consumes = "application/json", produces = "application/json")
	public Student student(@RequestBody Student student,
	                       @RequestParam("chinese") String chinese,
	                       @RequestParam("math") String math,
	                       @RequestHeader("token") String token) {
		System.out.println("接收到的json格式的对象为"+student);
		System.out.println("接收到的参数为"+chinese+"\t"+math+"\t"+token);
		System.out.println("接收到的header" + token);
		return student;
	}
	
	/*
	 * 路径参数
	 * http://localhost:8080/666/student/100
	 * */
	@GetMapping (value = "/{classId}/student/{id}")
	public Student student2(@PathVariable ("classId") String classId,
	                        @PathVariable ("id") String id) {
		System.out.println("接收到的路径参数为" + classId + "\t" + id);
		return new Student(id, "张三");
	}
}
